<template>
  <div class="container">
    <div style="text-align: center">
      <img src="~assets/images/PHPlogo.png" alt="logo" />
    </div>
    <div class="main">
      <div class="ant-form-item">
        <input
          placeholder="请输入手机号"
          type="text"
          v-model="data.phone"
          class="ant-input ant-input-lg"
        />
      </div>
      <div class="ant-form-item">
        <input
          placeholder="请输入密码"
          type="password"
          v-model="data.password"
          class="ant-input ant-input-lg"
        />
      </div>
      <div class="ant-form-item">
        <button class="ant-btn ant-btn-primary ant-btn-block" @click="login()">
          <span>登 录</span>
        </button>
      </div>
      <div class="ant-form-item" style="float: right">
        <button class="ant-btn ant-btn-red" @click="reg()">
          <span>注 册</span>
        </button>
      </div>
    </div>
  </div>
</template>
<script>
import { reactive } from "vue";
import { useRouter } from "vue-router";
import { Login } from "../../network/index.js";

export default {
  setup() {
    const router = useRouter();
    const go_url = () => {
      router.push({
        path: "/reg",
      });
    };

    const data = reactive({
      phone: "18811112222",
      password: "",
    });

    const login = () => {
      Login({
        phone: data.phone,
        password: data.password,
      }).then((e) => {
        if (e.user) {
          alert("登录成功");
          localStorage.setItem("token", e.user.token);
          router.push({
            path: "/index",
          });
        } else {
          alert(e);
        }
      });
    };

    const reg = () => {};

    return {
      go_url,
      data,
      login,
      reg,
    };
  },
};
</script>
<style scoped>
.container {
  position: relative;
  width: 100%;
  min-height: 100%;
  padding: 110px 0 144px;
  background-repeat: no-repeat;
  background-position: center 110px;
  background-size: 100%;
}
img {
  vertical-align: middle;
  border-style: none;
  width: 200px;
}
.main {
  width: 368px;
  min-width: 260px;
  margin: 50px auto;
}
.ant-form {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  color: rgba(0, 0, 0, 0.85);
  font-size: 14px;
  font-variant: tabular-nums;
  line-height: 1.5715;
  list-style: none;
  font-feature-settings: "tnum";
}
.ant-form-item {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  color: rgba(0, 0, 0, 0.85);
  font-size: 14px;
  font-variant: tabular-nums;
  line-height: 1.5715;
  list-style: none;
  font-feature-settings: "tnum";
  margin-bottom: 24px;
  vertical-align: top;
}
.ant-input {
  box-sizing: border-box;
  margin: 0;
  font-variant: tabular-nums;
  list-style: none;
  font-feature-settings: tnum;
  position: relative;
  display: inline-block;
  width: 100%;
  min-width: 0;
  padding: 4px 11px;
  color: #000000d9;
  font-size: 14px;
  line-height: 1.5715;
  background-color: #fff;
  background-image: none;
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  transition: all 0.3s;
}
.ant-input-lg {
  padding: 6.5px 11px;
  font-size: 16px;
}
.ant-btn {
  line-height: 1.5715;
  position: relative;
  display: inline-block;
  font-weight: 400;
  white-space: nowrap;
  text-align: center;
  background-image: none;
  border: 1px solid transparent;
  box-shadow: 0 2px 0 rgb(0 0 0 / 2%);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  touch-action: manipulation;
  height: 32px;
  padding: 4px 15px;
  font-size: 14px;
  border-radius: 2px;
  color: rgba(0, 0, 0, 0.85);
  background: #fff;
  border-color: #d9d9d9;
}
.ant-btn-primary {
  color: #fff;
  background: #1890ff;
  border-color: #1890ff;
  text-shadow: 0 -1px 0 rgb(0 0 0 / 12%);
  box-shadow: 0 2px 0 rgb(0 0 0 / 5%);
}
.ant-btn-block {
  width: 100%;
}
.ant-btn-red {
  color: #fff;
  background: #ff4d4f;
  border-color: #ff4d4f;
  text-shadow: 0 -1px 0 rgb(0 0 0 / 12%);
  box-shadow: 0 2px 0 rgb(0 0 0 / 5%);
}
</style>
